package com.lc.qianrenshiye;

import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.zcx.helper.activity.AppV4Activity;
import com.zcx.helper.glide.GlideLoader;

import cn.jpush.android.api.JPushInterface;

/**
 * Created by Administrator on 2016/3/14.
 */
public class BaseActivity extends AppV4Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //无title
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        //全屏
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
    }

    public void setBackTrue() {

        try {

            findViewById(R.id.title_ll).setVisibility(View.VISIBLE);
            findViewById(R.id.title_back_rl).setVisibility(View.VISIBLE);
            findViewById(R.id.title_back_rl).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    finish();
                }
            });

        } catch (Exception e) {

            e.printStackTrace();

        }

    }

    public void setBackTrueOrder() {

        try {

            findViewById(R.id.order_title_rl).setVisibility(View.VISIBLE);
            findViewById(R.id.order_title_back_rl).setVisibility(View.VISIBLE);
            findViewById(R.id.order_title_back_rl).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    finish();
                }
            });

        } catch (Exception e) {

            e.printStackTrace();

        }

    }

    public void setTitleNameOrder(String name) {

        try {

//            findViewById(R.id.title_name_tv).setVisibility(View.VISIBLE);
            if (name.length() > 10) {

                name = name.substring(0, 10) + "...";

            }
            ((TextView) findViewById(R.id.order_title_name_tv)).setText(name);

        } catch (Exception e) {

            e.printStackTrace();

        }

    }

    public void setTitleName(String name) {

        try {

//            findViewById(R.id.title_name_tv).setVisibility(View.VISIBLE);
            if (name.length() > 10) {

                name = name.substring(0, 10) + "...";

            }
            ((TextView) findViewById(R.id.title_name_tv)).setText(name);

        } catch (Exception e) {

            e.printStackTrace();

        }

    }

    public void setLogo() {

        findViewById(R.id.title_ll).setVisibility(View.VISIBLE);
        findViewById(R.id.title_logo_iv).setVisibility(View.VISIBLE);

    }


    //商家中心  右边title
    public void setRightName(String name, String s, int colorId, View.OnClickListener onClickListener) {

        try {

            findViewById(R.id.title_right_rl).setVisibility(View.VISIBLE);
            GlideLoader.getInstance().get(context, s, ((ImageView) findViewById(R.id.title_right_headimg_iv)), R.mipmap.login_logo, GlideLoader.TYPE_IMAGE_CIRCLE);

            if (name != null) {

                ((TextView) findViewById(R.id.title_right_business_name_tv)).setText(name);
            }
//            ((TextView) findViewById(R.id.title_right_business_name_tv)).setTextColor(ContextCompat.getColor(getApplicationContext(), colorId));
            findViewById(R.id.title_right_rl).setOnClickListener(onClickListener);

        } catch (Exception e) {

            e.printStackTrace();

        }

    }



    //设置页面的  右边title
    public void setRightName(String name, int colorId, View.OnClickListener onClickListener) {

        try {

            findViewById(R.id.title_right_no_net_rl).setVisibility(View.VISIBLE);

            ((TextView) findViewById(R.id.title_right_set_version_name_tv)).setText(name);
//            ((TextView) findViewById(R.id.title_right_set_version_name_tv)).setTextColor(ContextCompat.getColor(getApplicationContext(), colorId));
            findViewById(R.id.title_right_no_net_rl).setOnClickListener(onClickListener);

        } catch (Exception e) {

            e.printStackTrace();

        }

    }

    //收益页面  右边title
    public void setAllwanceRight(String name, int colorId, View.OnClickListener onClickListener) {

        try {

            findViewById(R.id.title_right_allowance_rl).setVisibility(View.VISIBLE);
            findViewById(R.id.title_bottom_line).setVisibility(View.GONE);

            ((TextView) findViewById(R.id.allwance_title_right_top_tv)).setText(name);
//            ((TextView) findViewById(R.id.allwance_title_right_top_tv)).setTextColor(ContextCompat.getColor(getApplicationContext(), colorId));
            findViewById(R.id.title_right_allowance_rl).setOnClickListener(onClickListener);

        } catch (Exception e) {

            e.printStackTrace();

        }

    }

////
////    public void setRightImage(View.OnClickListener onClickListener) {
////
////        try {
////
////
////            findViewById(R.id.title_right_ll).setVisibility(View.VISIBLE);
////            findViewById(R.id.title_share_ll).setVisibility(View.VISIBLE);
////            findViewById(R.id.title_collect_ll).setVisibility(View.VISIBLE);
////            findViewById(R.id.title_share_ll).setOnClickListener(onClickListener);
////            findViewById(R.id.title_collect_ll).setOnClickListener(onClickListener);
////
////
////        } catch (Exception e) {
////
////            e.printStackTrace();
////
////        }
////
////    }
//
    @Override
    protected void onResume() {
        super.onResume();

        JPushInterface.onResume(this);

        // 集成基本统计分析,初始化 Session
//        MobclickAgent.onResume(this);

    }

    @Override
    protected void onPause() {
        super.onPause();

        JPushInterface.onPause(this);

        // //集成基本统计分析, 结束 Session
//        MobclickAgent.onPause(this);

    }

}
